<?php

namespace app\Backend\controller;

use think\Controller;
use think\Request;
use app\common\model\Comment as CommentModel;

class Comment extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $comments = CommentModel::order('id', 'desc')->paginate(15);
        return view('', compact('comments'));
    }

        /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        $comment = CommentModel::find($id);
        if (!$comment) {
            $this->error('评论不存在！');
        }
        if (!$comment->delete()) {
            $this->error('删除失败，请稍后再试！');
        }
        $this->success('删除成功！');
    }

    /**
     * 审核功能
     * @param int $id
     */
    public function check(Request $request, $id)
    {
        $comment = CommentModel::find($id);
        if (!$comment) {
            $this->error('评论不存在！');
        }
        $status = $request->param('status');

        $comment->status = $status;
        if (!$comment->save()) {
            $this->error('操作失败，请稍后再试');
        }
        $this->success('操作成功！');
    }
}
